// --------------------------------------------------------------------------------------------------------------------
// <copyright file="CrashDumpsWrapper.cs" company="AzureContrib (Open source library http://azurecontrib.codeplex.com)">
//   Microsoft Public License (Ms-PL)
// </copyright>
// <summary>
//   Exception for errors when handling Windows Azure Cloud Drives.
// </summary>
// --------------------------------------------------------------------------------------------------------------------

using AzureContrib.WindowsAzure.Diagnostics.Properties;
using AzureContrib.WindowsAzure.ServiceRuntime;

using Microsoft.WindowsAzure.Diagnostics;

namespace AzureContrib.WindowsAzure.Diagnostics
{
	/// <summary>
	/// Wrapper around <see cref="CrashDumps"/>.
	/// </summary>
	/// <remarks>Will use [Export(typeof(ICrashDumps))].</remarks>
	internal class CrashDumpsWrapper : ICrashDumps
	{
		private readonly IRoleEnvironment roleEnvironment;
		private readonly ITrace trace;

		public CrashDumpsWrapper(
			/* [Import(RequiredCreationPolicy = CreationPolicy.Shared)] */ ITraceFactory traceFactory,
			/* [Import(RequiredCreationPolicy = CreationPolicy.Shared)] */ IRoleEnvironment roleEnvironment)
		{
			Assumes.NotNull(traceFactory, "traceFactory");
			Assumes.NotNull(roleEnvironment, "roleEnvironment");

			trace = traceFactory.Create(GetType());
			this.roleEnvironment = roleEnvironment;
		}

		public void EnableCollection(bool enableFullDumps)
		{
			if (!roleEnvironment.IsAvailable)
			{
				trace.Information(Strings.SettingCrashDumpsEnableCollectionNot, enableFullDumps);
				return;
			}

			trace.Information(Strings.SettingCrashDumpsEnableCollection, enableFullDumps);
			CrashDumps.EnableCollection(enableFullDumps);
		}

		public void EnableCollectionToDirectory(string directory, bool enableFullDumps)
		{
			if (!roleEnvironment.IsAvailable)
			{
				trace.Information(Strings.SettingCrashDumpsEnableCollectionToDirectoryNot, directory, enableFullDumps);
				return;
			}

			trace.Information(Strings.SettingCrashDumpsEnableCollectionToDirectory, directory, enableFullDumps);
			CrashDumps.EnableCollectionToDirectory(directory, enableFullDumps);
		}
	}
}